class application :
    def __init__ ( self , mediator ) :
        self . _mediator = mediator
        self . _application_window = None
        self . _any_key_event_replied = None
        self . _key_backspace_event_replied = None
        self . _key_ctrl_f5_event_replied = None
        self . _key_down_event_replied = None
        self . _key_escape_event_replied = None
        self . _key_f5_event_replied = None
        self . _key_return_event_replied = None
        self . _key_space_event_replied = None
        self . _key_up_event_replied = None
        self . _mouse_button_1_event_replied = None
    def application_window_request ( self ) :
        self . _mediator . application_window_reply ( self . _root_window )
    def gui_any_key_event_reply ( self , handler ) :
        self . _any_key_event_replied = handler
    def gui_create_application_window_reply ( self , window ) :
        self . _application_window = window
    def gui_global_mouse_button_1_event_reply ( self , handler ) :
        self . _mouse_button_1_event_replied = handler
    def gui_key_backspace_event_reply ( self , handler ) :
        self . _key_backspace_event_replied = handler
    def gui_key_ctrl_f5_event_reply ( self , handler ) :
        self . _key_ctrl_f5_event_replied = handler
    def gui_key_down_event_reply ( self , handler ) :
        self . _key_down_event_replied = handler
    def gui_key_escape_event_reply ( self , handler ) :
        self . _key_escape_event_replied = handler
    def gui_key_f5_event_reply ( self , handler ) :
        self . _key_f5_event_replied = handler
    def gui_key_return_event_reply ( self , handler ) :
        self . _key_return_event_replied = handler
    def gui_key_space_event_reply ( self , handler ) :
        self . _key_space_event_replied = handler
    def gui_key_up_event_reply ( self , handler ) :
        self . _key_up_event_replied = handler
    def key_escape_counter_request ( self ) :
        self . _mediator . key_escape_counter_reply ( self . _key_escape_counter )
    def quit_application ( self ) :
        del self . _any_key_event
        del self . _any_key_event_replied
        del self . _key_backspace_event
        del self . _key_backspace_event_replied
        del self . _key_ctrl_f5_event
        del self . _key_ctrl_f5_event_replied
        del self . _key_down_event
        del self . _key_down_event_replied
        del self . _key_escape_event
        del self . _key_escape_event_replied
        del self . _key_f5_event
        del self . _key_f5_event_replied
        del self . _key_return_event
        del self . _key_return_event_replied
        del self . _key_space_event
        del self . _key_space_event_replied
        del self . _key_up_event
        del self . _key_up_event_replied
        del self . _mouse_button_1_event
        del self . _mouse_button_1_event_replied
        self . _mediator . gui_quit_application ( self . _root_window )
    def run_main_loop ( self ) :
        self . _mediator . gui_global_mouse_button_1_event_request ( self . _root_window , self . _mediator . on_mouse_button_1 )
        self . _mediator . gui_key_backspace_event_request ( self . _root_window , self . _mediator . on_key_backspace )
        self . _mediator . gui_key_ctrl_f5_event_request ( self . _root_window , self . _mediator . on_key_ctrl_f5 )
        self . _mediator . gui_key_down_event_request ( self . _root_window , self . _mediator . on_key_down )
        self . _mediator . gui_key_escape_event_request ( self . _root_window , self . _on_key_escape )
        self . _mediator . gui_key_f5_event_request ( self . _root_window , self . _mediator . on_key_f5 )
        self . _mediator . gui_key_return_event_request ( self . _root_window , self . _mediator . on_key_return )
        self . _mediator . gui_key_space_event_request ( self . _root_window , self . _mediator . on_key_space )
        self . _mediator . gui_key_up_event_request ( self . _root_window , self . _mediator . on_key_up )
        self . _mediator . gui_any_key_event_request ( self . _root_window , self . _mediator . on_any_key )
        self . _any_key_event = self . _any_key_event_replied
        self . _key_backspace_event = self . _key_backspace_event_replied
        self . _key_ctrl_f5_event = self . _key_ctrl_f5_event_replied
        self . _key_down_event = self . _key_down_event_replied
        self . _key_escape_event = self . _key_escape_event_replied
        self . _key_f5_event = self . _key_f5_event_replied
        self . _key_return_event = self . _key_return_event_replied
        self . _key_space_event = self . _key_space_event_replied
        self . _key_up_event = self . _key_up_event_replied
        self . _mouse_button_1_event = self . _mouse_button_1_event_replied
        self . _mediator . enter_main_loop ( self . _root_window )
    def start ( self ) :
        self . _key_escape_counter = 0
        self . _mediator . gui_create_application_window_request ( )
        self . _root_window = self . _application_window
        self . _mediator . gui_set_application_window_title \
            ( self . _root_window
            , self . _mediator . localization_application_title ( )
            )
    def _on_key_escape ( self ) :
        self . _key_escape_counter += 1
        self . _mediator . on_key_escape ( )
